import Result from "@/model/Result";
import axios from "@/axios/api";
import User from "@/model/User";
import type Device from "@/model/Device";
import type PageQuery from "@/model/PageQuery";
import type Page from "@/model/Page";

export default class UserApi {

    static getLoginUser = async () => {
        return axios.get<Result<User>>(`/api/v1/user/getLoginUser`)
            .then(resp => {
            return resp.data
        })
    };

    static login = (user: User) => {
        return axios.post<Result<String>>('/api/v1/user/login', user)
    }


    static get = async (id: number) => {
        return await axios.get<Result<User>>(`/api/v1/user/${id}`)
            .then(resp => resp.data)
    }

    static remove = async (id: number) => {
        return await axios.delete<Result<User>>(`/api/v1/user/${id}`)
            .then(resp => resp.data)
    }

    static update = async (id: number, bean: User) => {
        return await axios.put<Result<void>>(`/api/v1/user/${id}`, bean)
            .then(resp => resp.data)
    }

    static save = async (bean: User) => {
        return await axios.post<Result<void>>(`/api/v1/user`, bean)
            .then(resp => resp.data)
    }

    static page = async (query: PageQuery) => {
        return await axios.post<Result<Page<User>>>(`/api/v1/user/page`, query)
            .then(resp => resp.data)
    }
}